<template>
  <div>
    <el-row style="margin: 10px 0">
      <el-col :span="8">
        <el-card style="color: #409EFF">
          <div><i class="el-icon-user-solid" /> 用户总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{map.users}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card style="color: #F56C6C">
          <div><i class="el-icon-money" /> 人物总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{map.items}}
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card style="color: #67C23A">
          <div><i class="el-icon-bank-card" /> 反馈总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{map.messages}}
          </div>
        </el-card>
      </el-col>
    </el-row>


    <el-row style="margin:50px 0">
      <el-col :span="8">
        <div>
          <div id="main" style="width: 100%; height: 450px"></div>
        </div>
      </el-col>

      <el-col :span="8">
        <div>
          <div id="main2" style="width: 100%; height: 450px"></div>
        </div>
      </el-col>

      <el-col :span="8">
        <div>
          <div id="main3" style="width: 100%; height: 450px"></div>
        </div>
      </el-col>
    </el-row>

    <el-row style="margin:30px 0">
      <el-col :span="8">
        <div>
          <div id="main4" style="width: 100%; height: 450px"></div>
        </div>
      </el-col>

      <el-col :span="8">
        <div>
          <div id="main5" style="width: 100%; height: 450px"></div>
        </div>
      </el-col>

      <el-col :span="8">
        <div>
          <div id="main6" style="width: 100%; height: 450px"></div>
        </div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "Home",
  data() {
    return {
      map: {}
    }
  },
  created() {
    this.$request.get("/echarts/counts").then(res => {
      this.map = res.data
    })
  },
  mounted() {  // 页面元素渲染之后再触发
    const option = {
      title: {
        text: '各人物分类数量统计',
        subtext: '柱状图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'bar'
        },
      ]
    };

    const option2 = {
      title: {
        text: '各人物分类数量统计',
        subtext: '折线图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line',
          smooth: true
        }
      ]
    };

    const option3 = {
      title: {
        text: '各人物分类数量统计',
        subtext: '饼图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: '',
          type: 'pie',
          radius: '50%',
          data: [
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    const option4 = {
      title: {
        text: '各诗人分类数量统计',
        subtext: '柱状图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'bar'
        },
      ]
    };

    const option5 = {
      title: {
        text: '各诗人分类数量统计',
        subtext: '折线图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line',
          smooth: true
        }
      ]
    };

    const option6 = {
      title: {
        text: '各诗人分类数量统计',
        subtext: '饼图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: '',
          type: 'pie',
          radius: '50%',
          data: [
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);

    var chartDom2 = document.getElementById('main2');
    var myChart2 = echarts.init(chartDom2);

    var chartDom3 = document.getElementById('main3');
    var myChart3 = echarts.init(chartDom3);

    var chartDom4 = document.getElementById('main4');
    var myChart4 = echarts.init(chartDom4);

    var chartDom5 = document.getElementById('main5');
    var myChart5 = echarts.init(chartDom5);

    var chartDom6 = document.getElementById('main6');
    var myChart6 = echarts.init(chartDom6);

    this.$request.get("/echarts/echarts").then(res => {
      // 填空
      option.xAxis.data = res.data.x
      option.series[0].data = res.data.y
      // 数据准备完毕之后再set
      myChart.setOption(option);
    })

    this.$request.get("/echarts/echarts2").then(res => {
      // 填空
      option2.xAxis.data = res.data.x
      option2.series[0].data = res.data.y
      // 数据准备完毕之后再set
      myChart2.setOption(option2);
    })

    this.$request.get("/echarts/echarts3").then(res => {
      // 填空
      option3.series[0].data = res.data
      // 数据准备完毕之后再set
      myChart3.setOption(option3);
    })

    this.$request.get("/echarts/echarts4").then(res => {
      // 填空
      option4.xAxis.data = res.data.x
      option4.series[0].data = res.data.y
      // 数据准备完毕之后再set
      myChart4.setOption(option4);
    })

    this.$request.get("/echarts/echarts5").then(res => {
      // 填空
      option5.xAxis.data = res.data.x
      option5.series[0].data = res.data.y
      // 数据准备完毕之后再set
      myChart5.setOption(option5);
    })

    this.$request.get("/echarts/echarts6").then(res => {
      // 填空
      option6.series[0].data = res.data
      // 数据准备完毕之后再set
      myChart6.setOption(option6);
    })
  }
}
</script>

<style scoped>

</style>
